package com.tanhua.manage.jobs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * @author xie
 * @date 2021/8/23
 */
@Component
public class AcceptVoiceJob {
    @Autowired
    private RedisTemplate<String,String> redisTemplate;

    @Scheduled(cron = "0/5 * * * * ?")
    public void acceptVoiceJob(){
        //同时设计一个定时器，每天的凌晨0点恢复所有的用户的语音次数状态~
        //查询redis中所有的键
        Set<String> keys = redisTemplate.keys("*");
        for (String key : keys) {
            //规范key 发送语音Key:SEND_NUM_ 接受语音：ACCEPT_NUM_
            //判断获取到的key是否包含SEND_NUM_或者ACCEPT_NUM_ 如果包含 就删除
           if(key.contains("SEND_NUM_")||key.contains("ACCEPT_NUM_")){
               redisTemplate.delete(key);
           }
        }
    }





}
